﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;

namespace Reports.Ticket
{
    public class Report1:DependencyObject
    {
        public static DependencyProperty StartDateProperty = DependencyProperty.Register("StartDate", typeof(DateTime), typeof(Report1));
        public DateTime StartDate
        {
            get { return (DateTime)GetValue(StartDateProperty); }
            set
            {
                SetValue(StartDateProperty, value);                
            }
        }
        public static DependencyProperty EndDateProperty = DependencyProperty.Register("EndDate", typeof(DateTime), typeof(Report1));
        public DateTime EndDate
        {
            get { return (DateTime)GetValue(EndDateProperty); }
            set
            {
                SetValue(EndDateProperty, value);
            }
        }        
        public Report1()
        {
            EndDate = DateTime.Now;
            if (DateTime.Now.Month > 1)
                StartDate = new DateTime(DateTime.Now.Year, DateTime.Now.Month -1, DateTime.Now.Day);
            else StartDate = new DateTime(DateTime.Now.Year-1, 12, DateTime.Now.Day);
        }
        public CrystalReport1 Load(TinyCinema.Bussiness.Login.Employee LoginInfo)
        {
            string sql = "select PHIM.TenPhim,LOAISUATCHIEU.TenLSC,COUNT(VE.MaVe) as Sove,SUM(Ve.Gia) as DoanhSo"
            + " from PHIM,VE,SUATCHIEU,LOAISUATCHIEU,DONGIASUATCHIEU"
            + " where PHIM.MaPhim = SUATCHIEU.MaPhim"
            + " and VE.MaSC=SUATCHIEU.MaSC"
            + " and SUATCHIEU.MaDG = DONGIASUATCHIEU.MaDG"
            + " and DONGIASUATCHIEU.MaLSC = LOAISUATCHIEU.MaLSC"
            + " and SUATCHIEU.NgayChieu>='" + StartDate + "'"
            + " and SUATCHIEU.NgayChieu<='" + EndDate + "'"
            + " group by PHIM.TenPhim,LOAISUATCHIEU.TenLSC"
            + " order by PHIM.TenPhim,LOAISUATCHIEU.TenLSC";
            CrystalReport1 report = new CrystalReport1();
            report.SetDataSource(TinyCinema.Data.Execution.Excute(sql));
            report.SetParameterValue("StartDate", StartDate);
            report.SetParameterValue("EndDate", EndDate);
            report.SetParameterValue("EmployeeName", LoginInfo.Emp.Name);
            return report;
        }
    }
}
